# encoding: utf-8
# 项目名称： 常用设计模式
# @File  : 005-抽象工厂模式.py
# @Author: sun hao
# @Desc : 
# @Date  :   14:27 2024/10/29

from abc import abstractmethod, ABCMeta


# -------- 抽象产品 ----------
class PhoneShell(metaclass=ABCMeta):
    @abstractmethod
    def show_shell(self):
        pass


class CPU(metaclass=ABCMeta):
    @abstractmethod
    def show_cpu(self):
        pass


class OS(metaclass=ABCMeta):
    @abstractmethod
    def show_os(self):
        pass


# -------- 抽象工厂 ----------
class PhoneFactory(metaclass=ABCMeta):
    @abstractmethod
    def make_shell(self):
        pass

    @abstractmethod
    def make_cpu(self):
        pass

    @abstractmethod
    def make_os(self):
        pass


# -------- 具体产品 ----------
class SmallShell(PhoneShell):
    def show_shell(self):
        print("普通手机-小手机壳")


class BigShell(PhoneShell):
    def show_shell(self):
        print("普通手机-大手机壳")


class AppleShell(PhoneShell):
    def show_shell(self):
        print("苹果手机壳")


class SnapDragonCPU(CPU):
    def show_cpu(self):
        print("晓龙CPU")


class MediaTekCPU(CPU):
    def show_cpu(self):
        print("联发科CPU")


class AppleCPU(CPU):
    def show_cpu(self):
        print("苹果CPU")


class Android(OS):
    def show_os(self):
        print("Android系统")


class IOS(OS):
    def show_os(self):
        print("IOS系统")


# -------- 具体产品 ----------

class MiFactory(PhoneFactory):
    """"
        小米手机
    """

    def make_cpu(self):
        return SnapDragonCPU()

    def make_os(self):
        return Android()

    def make_shell(self):
        return BigShell()


class HuaWeiFactory(PhoneFactory):
    """"
        华为手机
    """

    def make_cpu(self):
        return MediaTekCPU()

    def make_os(self):
        return Android()

    def make_shell(self):
        return BigShell()


class IPhoneFactory(PhoneFactory):
    """"
        苹果手机,只能配这3个
    """

    def __init__(self):
        print("生产苹果手机")

    def make_cpu(self):
        return AppleCPU()

    def make_os(self):
        return IOS()

    def make_shell(self):
        return AppleShell()


# -------- 客户端 ----------
class Phone:
    def __init__(self, cpu, os, shell):
        self.cpu = cpu
        self.os = os
        self.shell = shell

    def show_info(self):
        print("手机配置")
        self.cpu.show_cpu()
        self.os.show_os()
        self.shell.show_shell()


def make_phone(factory):
    print("开始生产手机")
    cpu = factory.make_cpu()
    os = factory.make_os()
    shell = factory.make_shell()
    return Phone(cpu, os, shell)


# 开始生产手机,设置工厂模式
p1 = make_phone(IPhoneFactory())
p1.show_info()
